package com.top.art.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.top.art.annotation.PermissionLimit;
import com.top.art.bo.*;
import com.top.art.exception.ArtException;
import com.top.art.manager.ExaminationPaperManager;
import com.top.art.service.IExaminationPaperService;
import com.top.art.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 试卷管理前端控制器
 * </p>
 *
 * @author hjh
 * @since 2020 -10-04
 */
@RestController
@RequestMapping("/paper")
public class ExaminationPaperController {

    /**
     * manage
     */
    @Resource
    private ExaminationPaperManager examinationPaperManager;

    @Autowired
    private IExaminationPaperService examinationPaperService;

    /**
     * Count res vo.
     *
     * @return the res vo
     */
    @GetMapping(value = "count")
    public ResVO<PaperCountVO> count(String studioCode) {
        PaperCountVO vo = examinationPaperManager.count(studioCode);
        return new ResVO<>(vo);
    }

    /**
     * Page res vo.
     *
     * @param bo the bo
     * @return the res vo
     */
    @PostMapping(value = "page")
    public ResVO<Page<ExaminationPaperVO>> page(@Validated @RequestBody ExaminationPaperPageBO bo) {
        Page<ExaminationPaperVO> page = examinationPaperManager.page(bo);
        return new ResVO<>(page);
    }

    /**
     * Update res vo.
     *
     * @param bo the bo
     * @return the res vo
     */
    @PostMapping(value = "update")
    public ResVO<Boolean> update(@Validated @RequestBody PaperBO bo) {
        boolean result = examinationPaperManager.update(bo);
        return new ResVO<>(result);
    }

    /**
     * Delete res vo.
     *
     * @param paperId the paper id
     * @return the res vo
     */
    @GetMapping(value = "/delete/{paperId}")
    public ResVO<Boolean> delete(@PathVariable Long paperId) {
        if (paperId == null) {
            throw new ArtException(500, "paperId不能为null");
        }
        boolean result = examinationPaperManager.delete(paperId);
        return new ResVO<>(result);
    }

    /**
     * Upload res vo.
     *
     * @param bo the bo
     * @return the res vo
     */
    @PostMapping(value = "upload")
    public ResVO<UploadVO> upload(@Validated @RequestBody UploadPaperBO bo) {
        UploadVO result = examinationPaperManager.upload(bo);
        return new ResVO<>(result);
    }

    /**
     * Agg res vo.
     *
     * @param
     * @return the res vo
     */
    @PostMapping(value = "/agg")
    public ResVO<PaperAggVO> agg(@RequestBody GradeBO bo) {
        PaperAggVO result = examinationPaperManager.agg(bo);
        return new ResVO<>(result);
    }

    /**
     * Grade res vo.
     *
     * @return the res vo
     */
    @PostMapping(value = "grade")
    public ResVO<List<PaperAggVO.StatsModelVO>> grade(@RequestBody GradeBO bo) {
        List<PaperAggVO.StatsModelVO> result = examinationPaperManager.grade(bo);
        return new ResVO<>(result);
    }

    /**
     * Page res vo.
     *
     * @param bo the bo
     * @return the res vo
     */
    @PostMapping(value = "query")
    public ResVO<Page<PaperQueryVO>> query(@Validated @RequestBody PaperQueryBO bo) {
        Page<PaperQueryVO> page = examinationPaperManager.query(bo);
        return new ResVO<>(page);
    }

    @PostMapping("/queryPaperDetail")
    @PermissionLimit(limit = false)
    public ResVO queryPaperDetail(@RequestBody StudioCourseBO bo) {
        return new ResVO<>(examinationPaperService.queryPaperDetail(bo));
    }

    @PostMapping(value = "/scarnCode")
    @PermissionLimit(limit = false)
    public ResVO<UploadVO> scarnCode(@Validated @RequestBody UploadPaperBO bo) {
        UploadVO result = examinationPaperManager.scarnCode(bo);
        return new ResVO<>(result);
    }

    @GetMapping(value = "/paperStatistic")
    @PermissionLimit(limit = false)
    public ResVO<List<PaperStatisticVO>> paperStatistic() {
        return new ResVO<>(examinationPaperManager.queryPaperStatistic());
    }

    @GetMapping(value = "/finish")
    public ResVO finish() {
        return new ResVO(examinationPaperManager.finishReviewPaper());
    }

    @GetMapping(value = "/start")
    public ResVO start() {
        return new ResVO(examinationPaperManager.startReviewPaper());
    }



}
